/*******************************************************************************
 * Copyright (c) 2014. konbluesky  (blackjackhoho@gmail.com)
 * Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 ******************************************************************************/

package com.fysports.web.module.menu;

import com.google.common.collect.Lists;
import com.fysports.web.kit.tree.ITreeBuilder;
import com.fysports.web.kit.tree.SystemMenuTreeBuilder;
import com.fysports.web.kit.tree.TreeNode;
import com.fysports.web.model.system.SystemMenu;
import com.fysports.web.module.core.BaseWebManagerModule;
import com.fysports.web.module.core.ModuleException;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 左侧菜单树
 * Created by konbluesky
 * Date : 14-7-1 下午4:12
 * Project : simple.jiren
 */
public class SystemManagerLeftMenuModule extends BaseWebManagerModule {

    private final static String REQ_VIEW_LEFTMENU = "leftMenuView";
    private final static String REQ_VIEW_CURNODE = "leftMenuCurNode";
    /*根节点id，用来显示的第一个节点*/
    private final static String ROOT = "1";
    private String nid;
    /*当前节点*/
    //    private String curNode;
    private ITreeBuilder<SystemMenu> builder;


    public SystemManagerLeftMenuModule(HttpServletRequest req) {
        super(req);
        this.nid = ROOT;
    }


    @Override public void execute() throws ModuleException {
        try {

            builder = new SystemMenuTreeBuilder();

            List<TreeNode<SystemMenu>> list = builder.builderTree(SystemMenu.dao.getChilds(nid));

            if (list == null || list.isEmpty())
                list = Lists.newArrayList();

            setAttr(REQ_VIEW_LEFTMENU, list);
            //            setAttr(REQ_VIEW_CURNODE, curNode);
        }
        catch (Exception e) {
            throw new ModuleException(e);
        }
    }

}
